package com.szpt.TrainingAssistant.sync;

import java.util.Date;

import com.szpt.TrainingAssistant.sql.TrainingDAO;
import com.szpt.TrainingAssistant.sql.TrainingRecord;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class Sync {
	public static void exec(Context mContext) {
		TrainingDAO mTrainingDAO = new TrainingDAO(mContext);
		
		mTrainingDAO.addRecord(new TrainingRecord(1, "12345,123,123,123123", new Date(System.currentTimeMillis())), false);
		mTrainingDAO.addRecord(new TrainingRecord(1, "12345123123,123,123,123123", new Date(System.currentTimeMillis())), false);
		mTrainingDAO.addRecord(new TrainingRecord(1, "1234512312312313123123,123,123,123123", new Date(System.currentTimeMillis())), false);
		
		SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
		Encoder mEncoder = new Encoder(Prefs.getString("username", null), Prefs.getString("password", null));
		mEncoder.addRecords(mTrainingDAO.getUnSyncedRecord());
		
		Poster mPoster = new Poster("http://10.1.33.139:1008/21");
		mPoster.addParams("json", mEncoder.toString());
		Log.d("webresult", mPoster.post());
	}
}